<?php
/*! \brief
 *  This is WFL10N class
 *  This class handles getting L10N string from language xml file
 * \author William Su
 */
class WFL10N {
    /**
     * @var WF
     */
    protected $objFramework;
    /**
     * @var WFWidgetPoolFactory
     */
    protected $objWidgetPoolFactory;
    /**
     * @var WFLangFileManager
     */
    protected $objLangFileManager;
    /**
     * @var WFConfig
     */
    protected $objConfig;
    protected $objSimpleXml;
    /**
     * @var WFDomFactory
     */
    protected $objDomFactory;
    public function __construct($objFramework){
        $this->objFramework = $objFramework;
        $this->objLangFileManager = $this->objFramework->getLangFileFactory($objFramework)->getLangFileManager();
        $this->objConfig = $this->objFramework->getConfigFactory($objFramework)->getConfig();
        $this->objDomFactory = $this->objFramework->getDomFactory($objFramework);
        //$this->objSimpleXml = $this->objFramework
        $this->objWidgetPoolFactory = $this->objFramework->getWidgetPoolFactory($objFramework);
    }
    public function setObjWidgetPoolFactory($objWidgetPoolFactory){
    	$this->objWidgetPoolFactory = $objWidgetPoolFactory;
    }
    /**
     * - Get L10N string from $WGF_HOME/repository/widgetPool/wp[Max]/widgetBase/modProduct/lang/[lang].xml
     */    
    public function getModProductLabel($strStringId){
    	$ret = $this->objFramework->getLangFactory()->getProductL10N('modProduct')->getLabelText($strStringId);
    	return $ret;
    }
    /**
     * - Get L10N string from $WGF_HOME/repository/widgetPool/wp[Max]/lang/[lang].xml
     */    
    public function getWFLabel($strStringId){
    	$ret = $this->objFramework->getLangFactory()->getWFL10N()->getLabelText($strStringId);
    	return $ret;
    }
    /**
     * - Get arrWidgetBaseName got en_US.xml file
     */    
    public function getArrWidgetBaseNameGotL10NFile(){
    	$ret = array();
    	$arrWidgetBaseFolderName = array();
    	$strPath = $this->objWidgetPoolFactory->getWPHome().'/widgetBase';
    	$arrFileAndDir = scandir($strPath);
    	foreach($arrFileAndDir as $strFileAndDir){
    		if(false === strpos($strFileAndDir,'.')){ //if no ext, it is folder, EX:config.php is not folder
    			//var_dump($strFile);
    			if(file_exists($strPath.'/'.$strFileAndDir.'/lang/'.$this->objConfig->getCurrentLang().'.xml')){
    				$ret[] = $strFileAndDir;
    			}
    		}
    	}
    	return $ret;
    }
}
